//
//  BiliView.m
//  wulihan
//
//  Created by tang on 16/3/28.
//  Copyright © 2016年 tang. All rights reserved.
//

#import "BiliView.h"
#import "Header.h"



#define buttonpx            WithView/5.0


@interface BiliView ()
{
    UIImageView *imageView1;
    UILabel *lable1;
 
    UIImageView *imageView2;
    UILabel *lable2;

    UIImageView *imageView3;
    UILabel *lable3;

    UIImageView *imageView4;
    UILabel *lable4;

    UIImageView *imageView5;
    UILabel *lable5;

}

@end



@implementation BiliView


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setUserInteractionEnabled:YES];
        [self initUI];
        
    }
    return self;
}



- (void)initUI
{
    UIButton *button1 = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, buttonpx, 93.0)];
    [self addSubview:button1];
    
    UIButton *button2 = [[UIButton alloc] initWithFrame:CGRectMake(buttonpx, 0, buttonpx, 93.0)];
    [self addSubview:button2];

    UIButton *button3 = [[UIButton alloc] initWithFrame:CGRectMake(2*buttonpx, 0, buttonpx, 93.0)];
    [self addSubview:button3];

    UIButton *button4 = [[UIButton alloc] initWithFrame:CGRectMake(3*buttonpx, 0, buttonpx, 93.0)];
    [self addSubview:button4];

    UIButton *button5 = [[UIButton alloc] initWithFrame:CGRectMake(4*buttonpx, 0, buttonpx, 93.0)];
    [self addSubview:button5];

    [button1 setTag:1];
    [button2 setTag:2];
    [button3 setTag:3];
    [button4 setTag:4];
    [button5 setTag:5];
    
    [button1 addTarget:self action:@selector(selectNili:) forControlEvents:UIControlEventTouchUpInside];
    [button2 addTarget:self action:@selector(selectNili:) forControlEvents:UIControlEventTouchUpInside];
    [button3 addTarget:self action:@selector(selectNili:) forControlEvents:UIControlEventTouchUpInside];
    [button4 addTarget:self action:@selector(selectNili:) forControlEvents:UIControlEventTouchUpInside];
    [button5 addTarget:self action:@selector(selectNili:) forControlEvents:UIControlEventTouchUpInside];
    
    UIImage *image = nil;
    
    image = [UIImage imageNamed:@"oneweixuanzhong.png"];
    imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, image.size.width, image.size.height)];
    [imageView1 setCenter:CGPointMake(CGRectGetWidth(button1.bounds)/2.0, 36.0)];
    [imageView1 setImage:image];
    [button1 addSubview:imageView1];
    
    
    image = [UIImage imageNamed:@"two.png"];
    imageView2 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, image.size.width, image.size.height)];
    [imageView2 setCenter:CGPointMake(CGRectGetWidth(button1.bounds)/2.0, 36.0)];
    [imageView2 setImage:image];
    [button2 addSubview:imageView2];

    image = [UIImage imageNamed:@"three.png"];
    imageView3 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, image.size.width, image.size.height)];
    [imageView3 setCenter:CGPointMake(CGRectGetWidth(button1.bounds)/2.0, 36.0)];
    [imageView3 setImage:image];
    [button3 addSubview:imageView3];

    image = [UIImage imageNamed:@"four.png"];
    imageView4 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, image.size.width, image.size.height)];
    [imageView4 setCenter:CGPointMake(CGRectGetWidth(button1.bounds)/2.0, 36.0)];
    [imageView4 setImage:image];
    [button4 addSubview:imageView4];

    image = [UIImage imageNamed:@"five.png"];
    imageView5 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, image.size.width, image.size.height)];
    [imageView5 setCenter:CGPointMake(CGRectGetWidth(button1.bounds)/2.0, 36.0)];
    [imageView5 setImage:image];
    [button5 addSubview:imageView5];

    
    lable1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 66, buttonpx, 10.0)];
    [lable1 setText:@"正方形"];
    [lable1 setTextAlignment:NSTextAlignmentCenter];
    [self addSubview:lable1];
    
    lable2 = [[UILabel alloc] initWithFrame:CGRectMake(buttonpx, 66, buttonpx, 10.0)];
    [lable2 setText:@"3:4"];
    [lable2 setTextAlignment:NSTextAlignmentCenter];
    [self addSubview:lable2];
    
    lable3 = [[UILabel alloc] initWithFrame:CGRectMake(2*buttonpx, 66, buttonpx, 10.0)];
    [lable3 setText:@"4:3"];
    [lable3 setTextAlignment:NSTextAlignmentCenter];
    [self addSubview:lable3];
    
    lable4= [[UILabel alloc] initWithFrame:CGRectMake(3*buttonpx, 66, buttonpx, 10.0)];
    [lable4 setText:@"9:16"];
    [lable4 setTextAlignment:NSTextAlignmentCenter];
    [self addSubview:lable4];

    lable5 = [[UILabel alloc] initWithFrame:CGRectMake(4*buttonpx, 66, buttonpx, 10.0)];
    [lable5 setText:@"16:9"];
    [lable5 setTextAlignment:NSTextAlignmentCenter];
    [self addSubview:lable5];

    
    [lable1 setFont:[UIFont systemFontOfSize:10.0]];
    [lable2 setFont:[UIFont systemFontOfSize:10.0]];
    [lable3 setFont:[UIFont systemFontOfSize:10.0]];
    [lable4 setFont:[UIFont systemFontOfSize:10.0]];
    [lable5 setFont:[UIFont systemFontOfSize:10.0]];
    
    [lable1 setTextColor:uicolor(204, 204, 204)];
    [lable2 setTextColor:uicolor(204, 204, 204)];
    [lable3 setTextColor:uicolor(204, 204, 204)];
    [lable4 setTextColor:uicolor(204, 204, 204)];
    [lable5 setTextColor:uicolor(204, 204, 204)];
}




- (void)removeAllColor
{
    [lable1 setTextColor:uicolor(204, 204, 204)];
    [lable2 setTextColor:uicolor(204, 204, 204)];
    [lable3 setTextColor:uicolor(204, 204, 204)];
    [lable4 setTextColor:uicolor(204, 204, 204)];
    [lable5 setTextColor:uicolor(204, 204, 204)];
    
    [imageView1 setImage:[UIImage imageNamed:@"oneweixuanzhong.png"]];
    [imageView2 setImage:[UIImage imageNamed:@"two.png"]];
    [imageView3 setImage:[UIImage imageNamed:@"three.png"]];
    [imageView4 setImage:[UIImage imageNamed:@"four.png"]];
    [imageView5 setImage:[UIImage imageNamed:@"five.png"]];
}




//选择比例
- (void)selectNili:(UIButton *)sender
{
    [self removeAllColor];
    
    if (sender.tag == 1)
    {
        [imageView1 setImage:[UIImage imageNamed:@"one.png"]];
        [lable1 setTextColor:uicolor(255, 204, 0)];
    }
    else if (sender.tag == 2)
    {
        [imageView2 setImage:[UIImage imageNamed:@"twoxuanze.png"]];
        [lable2 setTextColor:uicolor(255, 204, 0)];
    }
    else if (sender.tag == 3)
    {
        [imageView3 setImage:[UIImage imageNamed:@"threexuanze.png"]];
        [lable3 setTextColor:uicolor(255, 204, 0)];
    }
    else if (sender.tag == 4)
    {
        [imageView4 setImage:[UIImage imageNamed:@"fourxuanze.png"]];
        [lable4 setTextColor:uicolor(255, 204, 0)];
    }
    else if (sender.tag == 5)
    {
        [imageView5 setImage:[UIImage imageNamed:@"fivexuanze.png"]];
        [lable5 setTextColor:uicolor(255, 204, 0)];
    }
    
    if (_MBiliViewDelegate && [_MBiliViewDelegate respondsToSelector:@selector(chooseBiLi:)]) {
        [_MBiliViewDelegate chooseBiLi:(int)sender.tag];
    }

}




//选择
- (void)setSelectInt:(int)selectInt
{
    [self removeAllColor];
    
    if (selectInt == 1)
    {
        [imageView1 setImage:[UIImage imageNamed:@"one.png"]];
        [lable1 setTextColor:uicolor(255, 204, 0)];
    }
    else if (selectInt == 2)
    {
        [imageView2 setImage:[UIImage imageNamed:@"twoxuanze.png"]];
        [lable2 setTextColor:uicolor(255, 204, 0)];
    }
    else if (selectInt == 3)
    {
        [imageView3 setImage:[UIImage imageNamed:@"threexuanze.png"]];
        [lable3 setTextColor:uicolor(255, 204, 0)];
    }
    else if (selectInt == 4)
    {
        [imageView4 setImage:[UIImage imageNamed:@"fourxuanze.png"]];
        [lable4 setTextColor:uicolor(255, 204, 0)];
    }
    else if (selectInt == 5)
    {
        [imageView5 setImage:[UIImage imageNamed:@"fivexuanze.png"]];
        [lable5 setTextColor:uicolor(255, 204, 0)];
    }

    if (_MBiliViewDelegate && [_MBiliViewDelegate respondsToSelector:@selector(chooseBiLi:)]) {
        [_MBiliViewDelegate chooseBiLi:selectInt];
    }
    
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
